<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
	//采用直接量的方式创建对象
	function f1() {
		var student={
				"name":"zhangsan",
				"age":26,
				"work":function(){
					alert("我学java");
				}
		};
		alert(student.name);
        alert(student.age);
        student.work();
		
	}
	//采用内置构造器创建对象
	function f2() {
		var teacher=new Object();
		teacher.name="苍老师";
		teacher.age=18;
		teacher.work=function(){
			alert("我教JAVA；");
		}
		alert(teacher.name);
        alert(teacher.age);
        teacher.work();
	}
	//自定义构造器
	//类名大写为构造器
	function Coder(name,age,work) {
		this.name=name;
	//this指代当前的对象
	//.job是给当前对象增加一个属性
	//=work是给这个属性的值
	
		this.age=age;
		this.job=work;
	}

	function f3() {
		var coder=new Coder(
			"Lisi",
			28,
			function() {
				alert("我写代码");
			}
		);
		alert(coder.name);
		alert(coder.age);
		coder.job();
	}
</script>
</head>
<body>
<p>三种方创建对象</p>
	<input type="button" value="按钮1" onclick="f1();"/>
	<input type="button" value="按钮2" onclick="f2();"/>
	<input type="button" value="按钮3" onclick="f3();"/>
</body>
</html>








































